Skip to content

fix(server): refuse a query on a column the table does not have - #63

Merged
grrowl merged 4 commits into
mainfrom
fix/unknown-columns
Nov 17, 2026
Merged

grrowl merged 4 commits into
mainfrom
fix/unknown-columns

Conversation

@grrowl

@grrowl grrowl commented Nov 17, 2026

Copy link
Copy Markdown
Owner

A where or orderBy that names a column the table does not have was not refused. The SQL compiler writes a column as a double quoted name, and SQLite in a Durable Object reads an unknown quoted name as a string literal. So eq(nope, "nope") returned every row in the snapshot, while the client's evaluator, which decides the deltas, matched none. A typo in a column name gave an app a wrong list that looked right. It reached every comparison, in, like, orderBy, fetch and readSyncSnapshot.

What changed

  • The columns a query names are checked against the table when the query is compiled. An unknown name is refused the way an unsupported predicate is: reset with nothing registered for a sub, an empty page for a fetch, and a rejection for readSyncSnapshot. The server logs one line.
  • A name in another letter case and rowid are refused too. SQLite resolves BODY to body and accepts rowid, but a row on the client has neither key.
  • Nothing is cached between queries, so a column added by a migration is accepted on the next query. The cost is one read of the column list for each query that names a column.
  • Restore after a wake checks persisted subscriptions. One whose predicate names a column that a migration dropped closes its socket with 1011. The client reconnects and that query is refused.

Things to know

  • Until refusals are made loud, a refused query reads as no results on the client. The README's known limitations now say so.
  • After a column is dropped and the object wakes, each client that held a subscription naming it reconnects once and reloads that collection in full. It does not loop.
  • Not caught: a column dropped while the object stays awake. Live subscriptions read it as undefined until the next wake or reconnect.

Verification

  • 50 tests, written first. 46 of the first 48 failed on main; the other two hold before and after by design.
  • An adversarial review by a different model ran the tests, the full suite and nine mutations of the check in workerd. Verdict: mergeable. It asked for one more pin (the ties statement of a cursor fetch) and for text; both are in.
  • Typecheck and the full suite pass on @tanstack/db 1.0.0-rc.1.5 and 0.8.6.

Not verified: whether Cloudflare bills the rows read from the pragma, and the client's steps after a restore close, which were checked by reading the code.

The decision is a dated amendment to ADR-0013.

🤖 Generated with Claude Code

grrowl and others added 4 commits November 17, 2026 15:33
SQLite reads a double quoted name that matches no column as a string
literal, in WHERE and ORDER BY alike, so a sub, fetch or snapshot read
naming an unknown column returned every row or none, while the evaluator
that decides deltas read the column as undefined. SQLite also resolves a
name in another case and rowid, which a row from SELECT * never carries.

compileSubsetQuery now returns the columns a query names, and the mixin
refuses one not in pragma_table_xinfo (exact match), read only when the
query names a column and never cached across queries. A sub gets reset,
a fetch the empty page, readSyncSnapshot throws. A restored sub whose
where names a dropped column closes its socket with 1011, like one that
no longer compiles. ADR-0013 amendment 2026-11-17.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n columns

The one cursor case named the unknown column in both halves, so checking
only the page statement's columns still passed every test while the ties
statement returned every row. Each half is now pinned alone. One
readSyncSnapshot case goes through the RPC stub, where the caller gets a
plain Error whose message starts with UnsupportedPredicateError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ADR amendment now says what a client goes through when a restored
sub names a dropped column, why running the whole compiler on restore is
safe within one build, the rows read per column check, that the error
class does not survive the RPC, and what a dropped table gives. The
README lists the refusal under known limitations. The mixin drops the
`hidden != 1` filter, which no synced table can reach, and its restore
comment says the same as the ADR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merges the fix: the column names a query refers to are checked against the
table when the query is compiled, on every path that takes a client where or
orderBy, and on restore after a wake. Adds the changelog entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@grrowl
grrowl merged commit 8a8fb09 into main Nov 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant